package leetcode.L500;

import java.util.LinkedList;
import java.util.Queue;

public class EX200 {
    //bfs
/*    public static void main(String[] args) {
        char[][] grid = {{'1','1','1'},{'0','1','0'},{'1','1','1'}};

        int n = grid.length;

        int m = grid[0].length;
        int res = 0;

        Queue<int[]> queue = new LinkedList<>();

        for(int i = 0;i<n;i++){
            for(int j = 0;j<m;j++){
                if(grid[i][j]=='1'){
                    res++;

                    queue.offer(new int[]{i,j});
                    while(!queue.isEmpty()){
                        int[] cell = queue.poll();
                        int x = cell[0],y = cell[1];
                        grid[x][y]='0';

                        int x1 = x-1,y1 = y; //左
                        int x2 = x+1,y2 = y; //右
                        int x3 = x,y3 = y-1; //上
                        int x4 = x,y4 = y+1; //下
                        if(x1>=0&&grid[x1][y1]=='1'){
                            queue.offer(new int[]{x1,y1});
                        }
                        if(x2<n&&grid[x2][y2]=='1'){
                            queue.offer(new int[]{x2,y2});
                        }
                        if(y3>=0&&grid[x3][y3]=='1'){
                            queue.offer(new int[]{x3,y3});
                        }
                        if(y4<m&&grid[x4][y4]=='1'){
                            queue.offer(new int[]{x4,y4});
                        }
                    }
                }

            }
        }
        System.out.println(res);
    }*/

    public static void main(String[] args) {
        
    }


}
